<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./jquery.js"></script>
</head>

<body>

</body>
<script type="module">
    let a = "树"
    let b = "蓝车"
    console.log(a + "火" + b);
    console.log(`${a}火${b}`);
    // let xu = new Promise((reslove,reject)=>{
    //     reslove('成功')
    // })
    function ren(age, like) {
        return {
            age,
            like
        }
    }
    console.log(ren(1, 2));
    let xu = { a: 1, b: 2 }
    for (const key in xu) {
        console.log(key);
    }
    let xu1 = [1, 2, 3, 4, 5]
    for (const value of xu1) {
        console.log(value);
    }
    let z = {
        name: "树",
        azhe() {
            console.log(this.name);
        }
    }
    z.azhe()
    console.log(Object.keys(xu));
    console.log(Object.values(xu));






    // var w = new XMLHttpRequest()
    // console.log(w);
    // w.open('get', 'bbb1.txt', true)
    // w.send()
    // w.onreadystatechange = function () {
    //     if (w.readyState == 4) {
    //         if (w.status == 200) {
    //             console.log(w.responseText);
    //         }else {
    //             console.log(w.status);
    //         }

    //     }
    // }
    // var w = new XMLHttpRequest()
    // console.log(w);
    // w.open('get','bbb.txt',true)
    // w.onreadystatechange = function() {
    //      if(w.readyState == 4){
    //          if(w.status == 200){
    //              console.log(w.responseText);
    //          }
    //      }
    // }
    // w.send()
    // let u = new Promise(function(resolve,reject){
    //      resolve('成功')
    // })
    // u.then((res)=>{
    //     console.log(res);
    // }).catch((err)=>{
    //     console.log(err);
    // }).finally(()=>{
    //     console.log('一定执行');
    // })





    let b1 = new Promise(function (resolve, reject) {
        $.ajax({
            url: 'bbb.txt',
            success: function (res) {
                resolve(res)
            },
            error: function (err) {
                reject(err)
            }
        })
    })
    b1.then(res => {
        console.log(res);
    }).catch(err => {
        console.log(err);
    }).finally(() => {
        console.log('aaa');
    })
    // 封装ajax

    function ajax(url, resolve, reject) {
        var w = new XMLHttpRequest()
        console.log(w);
        w.open('get', url, true)
        w.send()
        console.log(w);
        w.onreadystatechange = function () {
            if (w.readyState == 4) {
                if (w.status == 200) {
                    resolve(w.responseText)
                } else {
                    reject(w.statusText)
                }

            }
        }
    }

    ajax('bbb.txt', function (res) {
        console.log(res);
    }, function (err) {
        console.log(err);
    })




    function fn(res, fn2) {
        // console.log(res, fn2);
        fn2(11111111)
    }

    fn(1, function (data) {
        console.log(data);
    })
    // 封装ajax中url
    function axios(url) {
        return new Promise(function (resolve, reject) {
            $.ajax({
                url: url,
                success: function (res) {
                    resolve(res)
                },
                error: function (err) {
                    reject(err)
                }
            })
        })
    }
    let c1 = axios('bbb.txt')
    console.log('结果',c1); 
</script>
<style>

</style>

</html>